package KuangShen.ZhuJieHeFanShe;
//测试Class类的创建方式有哪些
public class getClassTest {
    public static void main(String[] args) {
        Person person=new Student();
        System.out.println("这个人是"+person.name);

        //方式一：通过对象获得
        Class c1 = person.getClass();

        //方式二：forName获得
        try {
            Class c2 = Class.forName("KuangShen.ZhuJieHeFanShe.Student");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        //方式三：通过类名.class获得
        Class c3=Student.class;

        //方式四：基本内置类型的包装类都有一个Type属性(只有内置，不是每个类都行)
        Class<Integer> c4 = Integer.TYPE;

        //获得父类类型
        Class c5 = c1.getSuperclass();
        System.out.println(c5);

    }
}

class Person{
    String name;

    public Person() {

    }

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person{
    public Student(){
        this.name="学生";
    }
}

class Teacher extends Person{
    public Teacher(){
        this.name="老师";
    }
}